
#include <LengthUnitConversion.h>
#include <algorithm>
#include <assert.h>

using namespace std;

LengthUnitConversion::LengthUnitConversion()
{
	insertNewUnit( MILE);
	insertNewUnit( YARD);
	insertNewUnit( FEET);
	insertNewUnit( INCH);
}

void LengthUnitConversion::formatUnit( ostream& os, unsigned int remainingAmmount, const LengthUnit &fromUnit, const LengthUnit &toUnit ) const
{
	typedef std::vector<LengthUnit>::const_iterator UnitIterator;

	UnitIterator first = find( unitList_m.begin(), unitList_m.end(), fromUnit );		
	UnitIterator last = find( unitList_m.begin(), unitList_m.end(), toUnit  );	

//	assert( (first == unitList_m.end()) || (last == unitList_m.end()) );

	for( ; first != last; ++first )
	{
		first->formatThisUnit( os, remainingAmmount );
	}

	first->formatThisUnit( os, remainingAmmount );	
}

void LengthUnitConversion::insertNewUnit( const LengthUnit &unit )
{
	unitList_m.push_back( unit );

//	sort( unitList_m.begin(), unitList_m.end() );
}

LengthUnitConversion& LengthUnitConversion::getLengthUnitConversion()
{
	static LengthUnitConversion lengthUnitConversion;

	return lengthUnitConversion;
}


